package main

import (
	"gitee.com/hakwolf/taibak/internal/models"
	"gitee.com/hakwolf/taibak/internal/routers/dhost"
	"github.com/ying32/govcl/vcl"
	"github.com/ying32/govcl/vcl/types"
	"strings"
)

var taskhosts []models.DHost

//::private::
type TFmTaskEditFields struct {
}

func (f *TFmTaskEdit) OnCBDBTypeChange(sender vcl.IObject) {

}

func (f *TFmTaskEdit) OnSBTaskOKClick(sender vcl.IObject) {
	if strings.TrimSpace(f.EDShiLiname.Text()) == "" {
		vcl.ShowMessage("任务名称不能为空！")
		return
	}

	if f.CBExEType.ItemIndex() <= 0 {
		//f.SetModalResult(types.MrCancel)
		vcl.ShowMessage("请选择执行模式！")
		return

	}

	if f.CBShiLi.ItemIndex() <= 0 {
		//f.SetModalResult(types.MrCancel)
		vcl.ShowMessage("请选择实例！")
		return

	}

	f.SetModalResult(types.MrOk)

}

func (f *TFmTaskEdit) OnRBMinuteClick(sender vcl.IObject) {

}

func (f *TFmTaskEdit) OnRadioButton2Click(sender vcl.IObject) {

}

func (f *TFmTaskEdit) OnRadioButton3Click(sender vcl.IObject) {

}

func (f *TFmTaskEdit) OnRBHourClick(sender vcl.IObject) {

}

func (f *TFmTaskEdit) OnRBDayClick(sender vcl.IObject) {

}

func (f *TFmTaskEdit) OnSBTaskCancleClick(sender vcl.IObject) {

}

func (f *TFmTaskEdit) OnCBShiTpChange(sender vcl.IObject) {

}

func (f *TFmTaskEdit) OnFormCreate(sender vcl.IObject) {

}

func (f *TFmTaskEdit) Init() {
	FmTaskEdit.CBExEType.Items().Clear()
	FmTaskEdit.CBExEType.Items().Add("请选择")
	FmTaskEdit.CBExEType.Items().Add("备份数据库")
	FmTaskEdit.CBExEType.Items().Add("执行sql")

	FmTaskEdit.CBShiLi.Items().Add("请选择")
	// models.Db = models.CreateSqliteDb()
	//hosts := dhost.UIAll()
	taskhosts = dhost.UIAll()
	//taskhosts = make([]models.DHost, len(hosts))
	for _, host := range taskhosts {
		//panel111 :=  NewFmShilipanel(f)
		//panel111.SetParent(f.PanelShili)
		//panel111.SetAlign(types.AlTop) //
		//panel111.Label1.SetCaption(host.Databasetype)
		////panel111.Label2.SetCaption(host.Name)  //本地或者远程
		//panel111.Label3.SetCaption(host.Name)
		//panel111.MainID = host.Id
		//panel111.Show()
		FmTaskEdit.CBShiLi.Items().Add(host.Name)
		//taskhosts[key] = host   //取值时倒时这里index是否要减一
	}

	f.RBDay.SetChecked(true)

	f.CBShiLiType.Items().Clear()
	f.CBShiLiType.Items().Add("请选择")
	f.CBShiLiType.Items().Add("SQLSERVER")  //SQLSERVER 存值为1 不管后面怎么改
	f.CBShiLiType.Items().Add("MYSQL")      //MYSQL 存值为2 不管后面怎么改值顺序咋变
	f.CBShiLiType.Items().Add("ORACAL")     //ORACAL 存值为3
	f.CBShiLiType.Items().Add("PostgreSQL") //PostgreSQL 存值为4
	f.CBShiLiType.SetItemIndex(0)

}

func (f *TFmTaskEdit) OnSPBOpenSqlFileClick(sender vcl.IObject) {
	if f.OpenDialogSqlFile.Execute() {
		f.EDSQLFilePath.SetText(f.OpenDialogSqlFile.FileName())
	}
}

func (f *TFmTaskEdit) OnCBExETypeChange(sender vcl.IObject) {
	if f.CBExEType.ItemIndex() == 2 {
		f.PanelSqlRight.SetVisible(true)
		f.CBSQLDBName.SetVisible(true)
		f.LBSQLDBname.SetVisible(true)
	} else {
		f.PanelSqlRight.SetVisible(false)
		f.CBSQLDBName.SetVisible(false)
		f.LBSQLDBname.SetVisible(false)
	}

}


func (f *TFmTaskEdit) OnCBShiLiChange(sender vcl.IObject) {

}


func (f *TFmTaskEdit) OnBTEditClick(sender vcl.IObject) {

}


func (f *TFmTaskEdit) OnRBMonthClick(sender vcl.IObject) {

}


func (f *TFmTaskEdit) OnRBWeekClick(sender vcl.IObject) {

}


func (f *TFmTaskEdit) OnRBONCEClick(sender vcl.IObject) {

}


func (f *TFmTaskEdit) OnTabWeekContextPopup(sender vcl.IObject, mousePos types.TPoint, handled *bool) {

}


func (f *TFmTaskEdit) OnCBbakdatabaseChange(sender vcl.IObject) {

}


func (f *TFmTaskEdit) OnSPBBakNetsahreClick(sender vcl.IObject) {

}


func (f *TFmTaskEdit) OnSPBTaskControlDelClick(sender vcl.IObject) {

}


func (f *TFmTaskEdit) OnSPBBakQiNiuClick(sender vcl.IObject) {

}


func (f *TFmTaskEdit) OnSPBBakFtpClick(sender vcl.IObject) {

}


func (f *TFmTaskEdit) OnSPBBakBaiduDiskClick(sender vcl.IObject) {

}

